package com.geping.etl.config;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import com.alibaba.fastjson.JSONObject;
import com.geping.etl.common.entity.Logs;
import com.geping.etl.common.service.*;
import com.geping.etl.common.util.Constants;
import com.geping.etl.utils.EnvUitl;
import com.geping.etl.utils.HttpUtil;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.geping.etl.common.entity.Sys_User;
import com.geping.etl.common.repository.Sys_UserRepository;
import com.geping.etl.utils.SpringContextUtil;


@Component
@Slf4j
public class Schedules {

    private final static Logger LOGGER = LoggerFactory.getLogger(Schedules.class);

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private SysLockUserService sysLockUserService;

    @Autowired
    private LogsSynService logsSynService;

    @Autowired
    private Sys_UserAndOrgDepartmentService sys_UserAndOrgDepartmentService;

/*   @Scheduled(cron = "59 59 23 * * *")
    public void timer(){
       try {
           sysLockUserService.lockUserWhenNotLoggedIn30Day();
       } catch (Exception e) {
           LOGGER.error("lockUserWhenNotLoggedIn30Day失败---->",e);
       }
   }*/

    /**
     * 每天18点和凌晨2点执行
     */
   /* @Scheduled(cron = "0 0 18,2 * * ?")
    public void  reportCreate(){
        try {
            LOGGER.info("定时任务："+System.currentTimeMillis());
            Map params = new HashMap();//请求参数
            String systemUrl = EnvUitl.props.getProperty("9")!=null?EnvUitl.props.getProperty("9"):"";
            if(StringUtils.isBlank(systemUrl)){
                LOGGER.info("reportCreate---> systemUrl is  blank");
                return;
            }
            List<Map<String,Object>> list = new ArrayList<>();
            list = jdbcTemplate.queryForList("select * from SYS_DEPARTMENT where IS_DELETE='N' ");
            String json = new Gson().toJson(list);
            params.put("json",json);
            String result = HttpUtil.sendPost(systemUrl+"createDayReport", params);
            System.out.println("result=="+result);
        } catch (Exception e) {
            LOGGER.error("reportCreate失败---->",e);
        }
    }*/

   /* @Scheduled(cron = "0 5/30 * * * ? ")
    public void scheduledUpdateLogs() {
        try {
            logsSynService.updateLogs();
        } catch (Exception e) {
            LOGGER.error("日志同步失败---->",e);
        }
    }*/

    /**
     * @description: 定时同步邮箱群组信息
     * @return: void
     * @author: jiangfeng.zhu
     * @date: 2022/6/20
     */
   /* @Scheduled(cron = "${synDeptEmails.cron}")
    public void synDeptEmails(){
        try {
            log.info("synDeptEmails start");
            if (Constants.TAIWAN_BANK_USER_ON.equals(EnvUitl.props.getProperty("taiwan.user"))) {
                //查询所有部门员工信息并分组，并将分组好的信息同步到个人银行项目供ftp使用
                sys_UserAndOrgDepartmentService.synUserInfoToPersonBank();
            } else {
                log.info("synDeptEmails taiwan.user config is not open");
            }
            log.info("synDeptEmails end");
        }catch (Exception e){
            log.error("synDeptEmails exception, e = {}", e);
        }
    }*/
}
